package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class returnPath {
	
	public String getpath(int did){
		Connection con = null;
		Statement st = null;
		ResultSet rs = null;
		String path = "";
		try {
			con = getConnection();
			st = con.createStatement();
			String sql = "select path from data_info where did ="+did;
			rs = st.executeQuery(sql);
			if (rs.next()) {
				path = rs.getString(1);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			free(con, st, rs);
		}
		return path;
	}
	

	private Connection getConnection() throws ClassNotFoundException,SQLException {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
		Connection con = DriverManager.getConnection(url, "scott", "tiger");
		return con;
	}

	private void free(Connection con, Statement st, ResultSet rs) {
	try {
		if (rs != null) {
			rs.close();
		}
		if (st != null) {
			st.close();
		}
		if (con != null) {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	}

}
